package cn.llming.basic.service.impl;

import cn.llming.basic.mapper.BaseMapper;
import cn.llming.basic.query.BaseQuery;
import cn.llming.basic.result.BaseResult;
import cn.llming.basic.service.IBaseService;
import cn.llming.org.domain.Department;
import cn.llming.org.query.DepartmentQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void insert(T t) {
        baseMapper.insert(t);
    }

    @Override
    @Transactional
    public void delete(Serializable id) {
        baseMapper.delete(id);
            }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public T getById(Serializable id) {
        return baseMapper.getById(id);
    }

    @Override
    public List<T> getAll() {
        return baseMapper.getAll();
    }

    @Override
    public BaseResult<T> getPageList(BaseQuery query) {
        //查询总条数
        long total=baseMapper.getTotal(query);
        //根据查询的总条数进行分页
        if(total>0){
            List<T> baseMapperPageList=baseMapper.getPageList(query);
            return new BaseResult(total,baseMapperPageList);
        }
        return new BaseResult<>();
    }

    @Override
    @Transactional
    public void batchDelete(List<Long> ids) {
            baseMapper.batchRemove(ids);
    }
}
